// 监听localStorage.setItem并派发事件
const customSetItem = function (key, newVal) {
    // 创建一个StorageEvent事件
    const newStorageEvent = document.createEvent("StorageEvent");
    const storage = {
        setItem: function (k, val) {
            localStorage.setItem(k, val)
            // 初始化创建的事件
            newStorageEvent.initStorageEvent("setItem", false, false, k, null, val, null, null)
            // 派发对象
            window.dispatchEvent(newStorageEvent)
        }
    }
    return storage.setItem(key, newVal)
};

const unFocus = () => {
    const _button = document.createElement("button")
    _button.style.position = "fixed"
    _button.style.opacity = 0
    document.body.appendChild(_button)
    _button.focus()
    _button.remove()
}

export {
    customSetItem,
    unFocus,
}